package com.wy.jparepo;

import com.wy.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    public Page<User> findByPage(int pageNo, int pageSize){
        PageRequest request = this.buildPageRequest(pageNo,pageSize);
        Page<User> sourceCodes= this.userRepository.findAll(request);
        return sourceCodes;
    }

    //构建PageRequest
    private PageRequest buildPageRequest(int pageNumber, int pagzSize) {
        return  PageRequest.of(pageNumber - 1, pagzSize);
    }
}

